#include "CDlg.h"

HWND CDlg::Create(LPCTSTR lpTemplate, HWND hParent) {
  HINSTANCE hInstance = ::GetModuleHandle(NULL);
  return ::CreateDialog(hInstance, lpTemplate, hParent, (DLGPROC)m_proc.Dispatch);
}

HWND CDlg::Create(UINT nIDTemplate, HWND hParent) {
  HINSTANCE hInstance = ::GetModuleHandle(NULL);
  return ::CreateDialog(hInstance, MAKEINTRESOURCE(nIDTemplate), hParent, (DLGPROC)m_proc.Dispatch);
}

INT_PTR CDlg::CreateBox(LPCTSTR lpTemplate, HWND hParent) {
  HINSTANCE hInstance = ::GetModuleHandle(NULL);
  return ::DialogBox(hInstance, lpTemplate, hParent, (DLGPROC)m_proc.Dispatch);
}

INT_PTR CDlg::CreateBox(UINT nIDTemplate, HWND hParent) {
  HINSTANCE hInstance = ::GetModuleHandle(NULL);
  return ::DialogBox(hInstance, MAKEINTRESOURCE(nIDTemplate), hParent,
      (DLGPROC)m_proc.Dispatch);
}

LONG CDlg::GetBaseUnits() {
  return ::GetDialogBaseUnits();
}

INT CDlg::GetCtrlID(HWND hCtrl) {
  return ::GetDlgCtrlID(hCtrl);
}

HWND CDlg::GetItem(int nIDItem) {
  return ::GetDlgItem(m_hWnd, nIDItem);
}

UINT CDlg::SetItemInt(int nIDItem, UINT uValue, BOOL bSigned) {
  return ::SetDlgItemInt(m_hWnd, nIDItem, uValue, bSigned);
}

UINT CDlg::GetItemInt(int nIDItem, BOOL * lpResult, BOOL bSigned) {
  return ::GetDlgItemInt(m_hWnd, nIDItem, lpResult, bSigned);
}

UINT CDlg::SetItemText(int nIDItem, LPTSTR lpString) {
  return ::SetDlgItemText(m_hWnd, nIDItem, lpString);
}

UINT CDlg::GetItemText(int nIDItem, LPTSTR lpString, int nMaxCount) {
  return ::GetDlgItemText(m_hWnd, nIDItem, lpString, nMaxCount);
}

HWND CDlg::GetNextTabItem(HWND hCtrl, BOOL bPrevious) {
  return ::GetNextDlgTabItem(m_hWnd, hCtrl, bPrevious);
}

HWND CDlg::GetNextGroupItem(HWND hCtrl, BOOL bPrevious) {
  return ::GetNextDlgGroupItem(m_hWnd, hCtrl, bPrevious);
}

VOID CDlg::MapRect(LPRECT lpRect) {
  ::MapDialogRect(m_hWnd, lpRect);
}

LRESULT CDlg::OnInit(HWND hDefCtrl, LPARAM lParam) {
  return ::DefWindowProc(m_hWnd, WM_INITDIALOG, (WPARAM)hDefCtrl, lParam);
}

LRESULT CDlg::OnMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) {
  switch (uMsg) {
    case WM_INITDIALOG:
      return OnInit((HWND)wParam, lParam);
    case WM_CREATE:
      return OnCreate((LPCREATESTRUCT)lParam);
    case WM_DESTROY:
      return OnDestroy();
    case WM_CLOSE:
      return OnClose();
    case WM_ENABLE:
      return OnEnable(wParam);
    case WM_COMMAND:
      return OnCommand(HIWORD(wParam), LOWORD(wParam), (HWND)lParam);
    case WM_NOTIFY:
      return OnNotify(wParam, (LPNMHDR)lParam);
    case WM_SHOWWINDOW:
      return OnShow(wParam, lParam);
    case WM_MOVE:
      return OnMove(LOWORD(lParam), HIWORD(lParam));
    case WM_MOVING:
      return OnMoving((LPRECT)lParam);
    case WM_ENTERSIZEMOVE:
      return OnEnterSizeMove();
    case WM_EXITSIZEMOVE:
      return OnExitSizeMove();
    case WM_SIZE:
      return OnSize(wParam, LOWORD(lParam), HIWORD(lParam));
    case WM_SIZING:
      return OnSizing(wParam, (LPRECT)lParam);
    case WM_PAINT:
      {
        PAINTSTRUCT ps;
        HDC hDC = BeginPaint(&ps);
        int nRet = OnPaint(hDC);
        EndPaint(&ps);
        return nRet;
      }
      break;
    case WM_ERASEBKGND:
      return OnErase((HDC)wParam);
    case WM_SETFOCUS:
      return OnSetFocus((HWND)wParam);
    case WM_KILLFOCUS:
      return OnKillFocus((HWND)wParam);
    case WM_TIMER:
      return OnTimer(wParam, (TIMERPROC)lParam);
    case WM_CHAR:
      return OnChar(wParam, LOWORD(lParam), HIWORD(lParam));
    case WM_KEYDOWN:
      return OnKeyDown(wParam, LOWORD(lParam), HIWORD(lParam));
    case WM_KEYUP:
      return OnKeyUp(wParam, LOWORD(lParam), HIWORD(lParam));
    case WM_SYSKEYDOWN:
      return OnSysKeyDown(wParam, LOWORD(lParam), HIWORD(lParam));
    case WM_SYSKEYUP:
      return OnSysKeyUp(wParam, LOWORD(lParam), HIWORD(lParam));
    case WM_LBUTTONDOWN:
      return OnLButtonDown(wParam, {LOWORD(lParam), HIWORD(lParam)});
    case WM_LBUTTONUP:
      return OnLButtonUp(wParam, {LOWORD(lParam), HIWORD(lParam)});
    case WM_LBUTTONDBLCLK:
      return OnLButtonDblClk(wParam, {LOWORD(lParam), HIWORD(lParam)});
    case WM_MBUTTONDOWN:
      return OnMButtonDown(wParam, {LOWORD(lParam), HIWORD(lParam)});
    case WM_MBUTTONUP:
      return OnMButtonUp(wParam, {LOWORD(lParam), HIWORD(lParam)});
    case WM_MBUTTONDBLCLK:
      return OnMButtonDblClk(wParam, {LOWORD(lParam), HIWORD(lParam)});
    case WM_RBUTTONDOWN:
      return OnRButtonDown(wParam, {LOWORD(lParam), HIWORD(lParam)});
    case WM_RBUTTONUP:
      return OnRButtonUp(wParam, {LOWORD(lParam), HIWORD(lParam)});
    case WM_RBUTTONDBLCLK:
      return OnRButtonDblClk(wParam, {LOWORD(lParam), HIWORD(lParam)});
    case WM_MOUSEMOVE:
      return OnMouseMove(wParam, {LOWORD(lParam), HIWORD(lParam)});
    case WM_MOUSEWHEEL:
      return OnMouseWheel(LOWORD(wParam), HIWORD(wParam),
          {LOWORD(lParam), HIWORD(lParam)});
  }
  return FALSE;
}

